import React from 'react';
import { TableTag } from '../../components';

const render_TableTag = (val, block) => (
  <span>
    <TableTag
      isUp={val > 0 ? true : false}
      value={val}
      percentage={false}
      backgroundToColor={block}
    />
  </span>
);

const render_span = (val) => <span>{val}%</span>;

export const COLUMNS = (block) => {
  return [
    {
      title: '本期',
      dataIndex: 'thisPeriod',
      key: 'thisPeriod',
      ellipsis: true,
      width: '16%',
    },
    {
      title: '同期',
      dataIndex: 'theSamePeriod',
      key: 'theSamePeriod',
      ellipsis: true,
      width: '16%',
    },
    {
      title: '同比',
      dataIndex: 'rate',
      key: 'rate',
      width: '28%',
      render: (val) => render_TableTag(val, block),
    },
    {
      title: '跳闸率',
      dataIndex: 'tripRate',
      key: 'tripRate',
      width: '20%',
      ellipsis: true,
      render: (val) => render_span(val, block),
    },
  ];
};
export const COLUMNS1 = (block) => {
  return [
    {
      title: '本期',
      dataIndex: 'thisPeriod',
      key: 'thisPeriod',
      ellipsis: true,
      width: '25%',
    },
    {
      title: '同期',
      dataIndex: 'theSamePeriod',
      key: 'theSamePeriod',
      ellipsis: true,
      width: '25%',
    },
    {
      title: '同比',
      dataIndex: 'rate',
      key: 'rate',
      width: '25%',
      render: (val) => render_TableTag(val, block),
    },
    {
      title: '跳闸率',
      dataIndex: 'tripRate',
      key: 'tripRate',
      width: '25%',
      ellipsis: true,
      render: (val) => render_span(val, block),
    },
  ];
};

export const handleEQUIPMENTTITLE = (block) => {
  return {
    tripBody: {
      title: '跳闸总次数',
      col: 2,

      headTitle: ['110kV以上开关', '10-35KV开关'],
      unitText: '次',
      columns: [
        [
          {
            title: '中心',
            dataIndex: 'centerName',
            key: 'centerName',
            width: '20%',
          },
          ...COLUMNS(block),
        ],
        COLUMNS1(block),
      ],
    },
    fanFaultBody: {
      title: '风机故障频次',
      col: 1,

      unitText: '',
      columns: [
        [
          {
            title: '中心',
            dataIndex: 'centerName',
            key: 'centerName',
            width: '25%',
          },
          {
            title: '本期',
            dataIndex: 'thisPeriod',
            key: 'thisPeriod',
            width: '25%',
          },
          {
            title: '同期',
            dataIndex: 'theSamePeriod',
            key: 'theSamePeriod',
            width: '25%',
          },
          {
            title: '同比',
            dataIndex: 'rate',
            key: 'rate',
            width: '25%',
            render: (val) => render_TableTag(val, block),
          },
        ],
      ],
    },
    mttrBody: {
      title: 'MTTR',
      col: 1,

      unitText: 'h',
      columns: [
        [
          {
            title: '中心',
            dataIndex: 'centerName',
            key: 'centerName',
            width: '25%',
          },
          {
            title: '本期',
            dataIndex: 'thisPeriod',
            key: 'thisPeriod',
            width: '25%',
          },
          {
            title: '同期',
            dataIndex: 'theSamePeriod',
            key: 'theSamePeriod',
            width: '25%',
          },
          {
            title: '同比',
            dataIndex: 'rate',
            key: 'rate',
            width: '25%',
            render: (val) => render_TableTag(val, block),
          },
        ],
      ],
    },
  };
};
